home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / cursor.swg / 0032_Extended Cursor Handling unit.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1997-05-30  |  9.0 KB  |  256 lines

  1.  
  2. { Author:  Chad Moore
  3.  
  4.   I have been writing my own multipurpose units for projects for quite some
  5.   time now, and I noticed how all of the cursor routines in the SWAG used
  6.   BIOS calls, well, I just happened to be writing an extended display unit
  7.   for use with my display unit, and I figured you all could enjoy my
  8.   routines.  They may not be as optomized as they could be, but they work.
  9.   So, in other words, rip it, steal it, use it, distribute it, etc.
  10.  
  11.   Some of them may screw up while using the Crt unit, because it keeps track
  12.   of cursor movement itself...  (remember, I have my OWN display unit...I
  13.   hate the Crt one)  Anyway, they all DO work, but I am not responsible for
  14.   any damages caused by these routines.  Oh, and the routines are all based
  15.   on 0 through whatever - 1, rather than 1 through whatever.  (the way the
  16.   computer would do it)
  17.  
  18.   If you would like to get information on the CRTC registers (the ones I
  19.   used for this), Mode-X, sound, XMS/EMS/conventional memory, 3-D graphics,
  20.   and much more, I recomend this book:
  21.  
  22.   PC Underground Unconventional Programming Topics
  23.   from Abacus...
  24.  
  25. }
  26.  
  27. { Extended alphanumeric display unit }
  28. unit XDisplay;
  29. {$G+} { Enable 286 instructions }
  30.  
  31. interface
  32.  
  33. procedure CursorOn;
  34.   { turns the cursor ON }
  35. procedure CursorOff;
  36.   { turns the cursor OFF }
  37. function CursorState : Boolean;
  38.   { returns TRUE if the cursor is ON }
  39. procedure CursorShape( StartScan, EndScan : Byte );
  40.   { defines the cursor shape }
  41. function GetCursorShape : Word;
  42.   { high 8 bits = startscan, low 8 bits = endscan }
  43. procedure CursorPosition( Column, Row : Byte );
  44.   { positions the cursor }
  45. function CursorColumn : Byte;
  46.   { returns the cursor column }
  47. function CursorRow : Byte;
  48.   { returns the cursor row }
  49.  
  50. implementation
  51.  
  52. procedure CursorOn; assembler;
  53. asm
  54.   MOV   DX,03D4H        { CRTC index register }
  55.   MOV   AL,0AH          { select register 0Ah }
  56.   OUT   DX,AL
  57.   INC   DX              { CRTC data register }
  58.   IN    AL,DX           { get status }
  59.   AND   AL,0DFH         { bit 5 = 0 (Cursor on) }
  60.   OUT   DX,AL
  61. end;
  62.  
  63. procedure CursorOff; assembler;
  64. asm
  65.   MOV   DX,03D4H        { CRTC index register }
  66.   MOV   AL,0AH          { select register 0Ah }
  67.   OUT   DX,AL
  68.   INC   DX              { CRTC data register }
  69.   IN    AL,DX           { get status }
  70.   OR    AL,20H          { bit 5 = 1 (Cursor off) }
  71.   OUT   DX,AL
  72. end;
  73.  
  74. function CursorState : Boolean; assembler;
  75. asm
  76.   MOV   DX,03D4H        { CRTC index register }
  77.   MOV   AL,0AH          { select register 0Ah }
  78.   OUT   DX,AL
  79.   INC   DX              { CRTC data register }
  80.   IN    AL,DX           { get status }
  81.   AND   AL,20H          { if bit 5 = 1, cursor is off }
  82.   CMP   AL,20H          { is bit 5 on? }
  83.   JE    @@cursoroff
  84.   MOV   AL,TRUE         { no, cursor is on }
  85.   JMP   @@done          { return }
  86. @@cursoroff:
  87.   MOV   AL,FALSE        { yes, cursor is off }
  88. @@done:
  89. end;
  90.  
  91. procedure CursorShape( StartScan, EndScan : Byte ); assembler;
  92. asm
  93.   MOV   DX,03D4H        { CRTC index register }
  94.   MOV   AL,0AH          { select register 0Ah }
  95.   OUT   DX,AL
  96.   INC   DX              { CRTC data register }
  97.   IN    AL,DX           { get status }
  98.   MOV   AH,StartScan
  99.   AND   AL,0E0H         { clear bits 0-4 }
  100.   OR    AL,AH           { bits 0-4 = StartScan, save bits 5-7 }
  101.   OUT   DX,AL
  102.   DEC   DX              { CRTC index register }
  103.   MOV   AL,0BH          { select register 0Bh }
  104.   OUT   DX,AL
  105.   INC   DX              { CRTC data register }
  106.   IN    AL,DX           { get status }
  107.   MOV   AH,EndScan
  108.   AND   AL,0E0H         { clear bits 0-4 }
  109.   OR    AL,AH           { bits 0-4 = EndScan, save bits 5-7 }
  110.   OUT   DX,AL
  111. end;
  112.  
  113. function GetCursorShape : Word; assembler;
  114. asm
  115.   MOV   DX,03D4H        { CRTC index register }
  116.   MOV   AL,0AH          { select register 0Ah }
  117.   OUT   DX,AL
  118.   INC   DX              { CRTC data register }
  119.   IN    AL,DX           { get status }
  120.   AND   AL,1FH          { clear bits 5-7 }
  121.   MOV   AH,AL           { AH = startscan }
  122.   DEC   DX              { CRTC index register }
  123.   MOV   AL,0BH          { select register 0Bh }
  124.   OUT   DX,AL
  125.   INC   DX              { CRTC data register }
  126.   IN    AL,DX           { get status }
  127.   AND   AL,1FH          { clear bits 5-7 }
  128. end;
  129.  
  130. procedure CursorPosition( Column, Row : Byte ); assembler;
  131. asm
  132.   { get cursor offset into BX }
  133.   MOV   DX,03D4H        { CRTC index register }
  134.   MOV   AL,13H          { select register 13H }
  135.   OUT   DX,AL
  136.   INC   DX              { CRTC data register }
  137.   IN    AL,DX
  138.   MOV   AH,AL           { store row offset in AH }
  139.   DEC   DX              { CRTC index register }
  140.   MOV   AL,14H          { select register 14H }
  141.   OUT   DX,AL
  142.   INC   DX              { CRTC data register }
  143.   IN    AL,DX
  144.   SHL   AH,01H          { multiply by 2 }
  145.   AND   AL,40H          { check bit 5 for doubleword addressing }
  146.   CMP   AL,00H          { doubleword? }
  147.   JE    @@continue      { no, continue }
  148.   SHL   AH,01H          { yes, multiply by 2 *more* }
  149. @@continue:
  150.                         { AH = row length }
  151.   SHR   AX,08H          { AX = row length }
  152.   MUL   Row             { row length * Row }
  153.   MOV   BL,Column
  154.   XOR   BH,BH
  155.   ADD   AX,BX           { + Column }
  156.   MOV   BX,AX           { BX = cursor offset }
  157.   { send BX to CRTC }
  158.   DEC   DX              { CRTC index register }
  159.   MOV   AL,0EH          { select register 0EH (cursor offset HIGH) }
  160.   OUT   DX,AL
  161.   INC   DX              { CRTC data register }
  162.   MOV   AL,BH           { get HIGH to send }
  163.   OUT   DX,AL
  164.   DEC   DX              { CRTC index register }
  165.   MOV   AL,0FH          { select register 0FH (cursor offset LOW) }
  166.   OUT   DX,AL
  167.   INC   DX              { CRTC data register }
  168.   MOV   AL,BL           { get LOW to send }
  169.   OUT   DX,AL
  170. end;
  171.  
  172. function CursorColumn : Byte; assembler;
  173. asm
  174.   { get cursor offset }
  175.   MOV   DX,03D4H        { CRTC index register }
  176.   MOV   AL,0EH          { select register 0Eh }
  177.   OUT   DX,AL
  178.   INC   DX              { CRTC data register }
  179.   IN    AL,DX
  180.   SHL   AX,08H          { AH = high bits }
  181.   DEC   DX              { CRTC index register }
  182.   MOV   AL,0FH          { select register 0Fh }
  183.   OUT   DX,AL
  184.   INC   DX              { CRTC data register }
  185.   IN    AL,DX           { AL = low bits }
  186.   MOV   CX,AX           { save cursor offset }
  187.   { get chars per line }
  188.   DEC   DX              { CRTC index register }
  189.   MOV   AL,14H          { select register 14h }
  190.   OUT   DX,AL
  191.   INC   DX              { CRTC data register }
  192.   IN    AL,DX           { doubleword addressing? }
  193.   MOV   BL,AL           { save in BL }
  194.   DEC   DX              { CRTC index register }
  195.   MOV   AL,13H          { select register 13h }
  196.   OUT   DX,AL
  197.   INC   DX              { CRTC data register }
  198.   IN    AL,DX           { get offset between 2 lines (line width) }
  199.   SHL   AL,01H          { multiply by 2 }
  200.   AND   BL,40H          { check bit 5 for doubleword addressing }
  201.   CMP   BL,00H          { doubleword? }
  202.   JE    @@continue      { no, continue }
  203.   SHL   AL,01H          { multiply by 2 *more* }
  204. @@continue:             { AL = chars per line }
  205.   { calculate }
  206.   XOR   AH,AH           { clear upper AX }
  207.   MOV   BX,AX           { get chars per line in BX }
  208.   XOR   DX,DX           { DX:AX gets ready for div }
  209.   MOV   AX,CX           { get cursor offset }
  210.   DIV   BX              { div DX = remainder, AX = answer }
  211.   MOV   AX,DX           { get remainder }
  212. end;
  213.  
  214. function CursorRow : Byte; assembler;
  215. asm
  216.   { get cursor offset }
  217.   MOV   DX,03D4H        { CRTC index register }
  218.   MOV   AL,0EH          { select register 0Eh }
  219.   OUT   DX,AL
  220.   INC   DX              { CRTC data register }
  221.   IN    AL,DX
  222.   SHL   AX,08H          { AH = high bits }
  223.   DEC   DX              { CRTC index register }
  224.   MOV   AL,0FH          { select register 0Fh }
  225.   OUT   DX,AL
  226.   INC   DX              { CRTC data register }
  227.   IN    AL,DX           { AL = low bits }
  228.   MOV   CX,AX           { save cursor offset }
  229.   { get chars per line }
  230.   DEC   DX              { CRTC index register }
  231.   MOV   AL,14H          { select register 14h }
  232.   OUT   DX,AL
  233.   INC   DX              { CRTC data register }
  234.   IN    AL,DX           { doubleword addressing? }
  235.   MOV   BL,AL           { save in BL }
  236.   DEC   DX              { CRTC index register }
  237.   MOV   AL,13H          { select register 13h }
  238.   OUT   DX,AL
  239.   INC   DX              { CRTC data register }
  240.   IN    AL,DX           { get offset between 2 lines (line width) }
  241.   SHL   AL,01H          { multiply by 2 }
  242.   AND   BL,40H          { check bit 5 for doubleword addressing }
  243.   CMP   BL,00H          { doubleword? }
  244.   JE    @@continue      { no, continue }
  245.   SHL   AL,01H          { multiply by 2 *more* }
  246. @@continue:             { AL = chars per line }
  247.   { calculate }
  248.   XOR   AH,AH           { clear upper AX }
  249.   MOV   BX,AX           { get chars per line in BX }
  250.   XOR   DX,DX           { DX:AX gets ready for div }
  251.   MOV   AX,CX           { get cursor offset }
  252.   DIV   BX              { div DX = remainder, AX = answer }
  253.                         { returns AL }
  254. end;
  255.  
  256. end.